<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/9/26
 * Time: 15:10
 */

namespace app\user\services;


use app\user\model\UserModel;
use think\Db;
use think\Model;

class UserService extends Model
{
    public static function newLogin($data){
        $account = isset($data['account'])?$data['account']:false;
        $password = isset($data['password'])?$data['password']:false;
        if(!$account || !$password){
             return [
                   'status' => '-1',
                   'msg' => '数据为空!'
               ];
        }
        
        $data = ['account'=>$account, 'password'=>$password];
        
        $user = new UserModel();

        return $user->interfaceDoName($data);
    }

    public static function register($data){
      $account = isset($data['account'])?$data['account']:false;
      $password = isset($data['password'])?$data['password']:false;
      if(!$account || !$password){
         return [
           'status' => '-1',
           'msg' => '数据为空!'
         ];
      }
      $result = Db::name("user")->where('user_login', $account)->find();
      if(!$result){
        $data  = [
            'user_login'      => $account,
            'user_nickname'   => $account,
            'user_pass'       => cmf_password($password),
            'last_login_ip'   => get_client_ip(0, true),
            'create_time'     => time(),
            'last_login_time' => time(),
            'user_status'     => 1,
            "user_type"       => 2,
        ];
        $userId = Db::name("user")->insertGetId($data);
        $data   = Db::name("user")->where('id', $userId)->find();
        cmf_update_current_user($data);
        return [ 'status' => '1', 'msg' => '注册成功'];
      }
      return [ 'status' => '-1','msg' => '该账号已存在!' ];
    }
    
}